package cn.jzvd.demo;

import android.app.Application;
import android.content.Context;

import com.blankj.utilcode.util.ToastUtils;
import com.danikula.videocache.HttpProxyCacheServer;

import io.objectbox.BoxStore;


/**
 * Created by Nathen
 * On 2015/12/01 11:29
 */
public class ApplicationDemo extends Application {

    private HttpProxyCacheServer proxy;
    private static Context context;

    public static HttpProxyCacheServer getProxy(Context context) {
        ApplicationDemo app = (ApplicationDemo) context.getApplicationContext();
        return app.proxy == null ? (app.proxy = app.newProxy()) : app.proxy;
    }

    @Override
    public void onCreate() {
        super.onCreate();

        ApplicationDemo.context = getApplicationContext();
//        LeakCanary.install(this);
        initDB();

    }

    private static BoxStore boxStore;
    private void initDB() {

        try{

            boxStore = MyObjectBox.builder().androidContext(getApplicationContext()).build();
        }catch (Exception e){
            ToastUtils.showShort("卸载重新装");
        }
    }

    public static BoxStore getBoxStore() {
        return boxStore;
    }

    private HttpProxyCacheServer newProxy() {
        return new HttpProxyCacheServer(this);
    }
}
